package com.aiti.lulian.controller.crad;

import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.annotates.AddGroup;
import com.aiti.lulian.annotates.EditGroup;
import com.aiti.lulian.annotates.QueryGroup;
import com.aiti.lulian.bo.CustomerFollowUpRecordBo;
import com.aiti.lulian.bo.ShangJiFollowUpRecordBo;
import com.aiti.lulian.entity.CustomerFollowUpRecord;
import com.aiti.lulian.service.ICustomerFollowUpRecordService;
import com.aiti.lulian.service.IShangJiFollowUpRecordService;
import com.aiti.lulian.vo.CustomerFollowUpRecordVo;
import com.aiti.lulian.vo.ShangjiFollowUpRecordVo;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 客户询盘跟进记录
 * @since 2024-11-12
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/card/record/sj")
public class ShangJiFollowUpRecordController extends WebController<CustomerFollowUpRecord> {

    private final IShangJiFollowUpRecordService baseService;

    /**
     * 查询客户的跟进记录
     * @param bo 前端传入的参数
     * @return 跟进的记录
     */
    @GetMapping("/list")
    public Message list(@Validated(QueryGroup.class) ShangJiFollowUpRecordBo bo) {
        Integer pageSize = bo.getPageSize();
        Integer pageNum = bo.getPageNum();
        Page<CustomerFollowUpRecord> page = startPage(pageNum,pageSize);
        Map<String, Object> result = baseService.queryCustomerList(page, bo);
        result.put("total", page.getTotal());
        return Message.success(result);
    }

    /**
     * 新增跟进记录
     * @param bo 参数
     * @return 结果
     */
    @PostMapping("/add")
    public Message addFollowUpRecord( @RequestBody ShangJiFollowUpRecordBo bo) {
        boolean b = baseService.addFollowUpRecord(bo);
        return Message.success(b);
    }

    /**
     * 查询某个记录的详情
     * @param bo 参数
     * @return 结果
     */
    @GetMapping("/queryCustomerFollowUpRecordDetail")
    public Message queryCustomerFollowUpRecordDetail(@Validated(QueryGroup.class) ShangJiFollowUpRecordBo bo) {
        ShangjiFollowUpRecordVo result = baseService.queryCustomerFollowUpRecordDetail(bo);
        return Message.success(result);
    }


    /**
     * 更新根进记录
     * @param bo 参数
     * @return 结果
     */
    @PostMapping("/update")
    public Message editCustomerFollowUpRecord(@RequestBody ShangJiFollowUpRecordBo bo) {
        return Message.success(baseService.editCustomerFollowUpRecord(bo));
    }

    @PostMapping("/delete")
    public Message deleteShangJiFollowUpRecord(@RequestBody ShangJiFollowUpRecordBo bo) {
        if(StringUtils.isBlank(bo.getBaseId())){
            return Message.fail("没有找到主键");
        }
        return Message.success(baseService.deleteShangJiFollowUpRecord(bo));
    }

    @PostMapping("/batchDelete")
    public Message batchDelete(@RequestBody ShangJiFollowUpRecordBo bo) {
        if(CollectionUtils.isEmpty(bo.getIds())){
            return Message.fail("没有找到主键");
        }
        baseService.removeByIds(bo.getIds());
        return Message.success();
    }

    /**
     * 商机跟进记录列表
     * @param bo 前端传入的参数
     * @return 跟进的记录
     */
    @GetMapping("/page")
    public Message page(@Validated(QueryGroup.class) ShangJiFollowUpRecordBo bo) {
        Integer pageSize = bo.getPageSize();
        Integer pageNum = bo.getPageNum();
        Page page = startPage(pageNum,pageSize);
        if(StringUtils.isEmpty(bo.getUserId())){
            bo.setUserId(findUserId());
        }
        return baseService.followUpPage(page, bo);
    }


}
